package com.ushio.commonmodule.pojo.result;

import lombok.Builder;
import lombok.Data;

import java.io.Serializable;
@Data
@Builder
public class Result<T> implements Serializable {
    private int code;
    private T data;
    private String msg;

    public boolean isSucc() {
        return this.getCode() == ResultCode.SUCCESS.getCode();
    }

    public static <T> Result<T> success() {
        return Result.<T>builder().code(ResultCode.SUCCESS.getCode()).msg(ResultCode.SUCCESS.getMsg()).build();
    }

    public static <T> Result<T> success(T data) {
        return Result.<T>builder().code(ResultCode.SUCCESS.getCode()).msg(ResultCode.SUCCESS.getMsg()).data(data).build();
    }

    public static <T> Result<T> success(ResultCode resultCode,T data) {
        return Result.<T>builder().code(resultCode.getCode()).msg(resultCode.getMsg()).build();
    }

    public static <T> Result<T> fail() {
        System.out.println(ResultCode.FAIL.getCode());
        return Result.<T>builder().code(ResultCode.FAIL.getCode()).msg(ResultCode.FAIL.getMsg()).build();
    }

    public static <T> Result<T> fail(String message) {
        return Result.<T>builder().code(ResultCode.FAIL.getCode()).msg(message).build();
    }

    public static <T> Result<T> fail(ResultCode resultCode) {
        return Result.<T>builder().code(resultCode.getCode()).msg(resultCode.getMsg()).build();
    }

    public static <T> Result<T> fail(ResultCode resultCode, String msg) {
        return Result.<T>builder().code(resultCode.getCode()).msg(msg).build();
    }

    public static <T> Result<T> fail(T data, ResultCode resultCode, String msg) {
        return Result.<T>builder().code(resultCode.getCode()).msg(msg).data(data).build();
    }

}

